package com.chen.service.Impl;

import com.chen.mapper.UserMapper;
import com.chen.pojo.User;
import com.chen.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;


@Transactional
@Service
public class UserSeriviceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public int addUser(User user) {
        int i = userMapper.addUser(user);
       if (i==1){
           System.out.println("添加成功");
       }
       return i;

    }

    @Override
    public List<User> queryAll() {
        List<User> userList = userMapper.queryAll();
        return  userList;
    }

    @Override
    public User queryById(Long id) {
        User user = userMapper.queryById(id);
        return user;
    }

    @Override
    public int updateUser(User user) {
        int i = userMapper.updateUser(user);
        if (i==1){
            System.out.println("更新成功");
        }
        return i;
    }

    @Override
    public int deleteUser(Long id) {
        int i = userMapper.deleteUser(id);
        if (i==1){
            System.out.println("删除成功");
        }
        return i;
    }

    @Override
    public User queryByName(String name) {
        User user = userMapper.queryByName(name);
        return  user;
    }
}
